import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.io.IOException;

public class JAPI_Windowlistener implements WindowListener
{

	JAPI_SocketOutputStream as;
	int id;
	int debuglevel=0;
	int type;

	public JAPI_Windowlistener(int object_id, JAPI_SocketOutputStream action , int t)
	{
		as = action;
		id = object_id;
		type = t;
	}


	public void windowActivated(WindowEvent e)
	{
		if(type==JAPI_Const.J_ACTIVATED)
			sendid();
	}

	public void windowDeactivated(WindowEvent e)
	{
		if(type==JAPI_Const.J_DEACTIVATED)
			sendid();
	}

	public void windowOpened(WindowEvent e)
	{
		if(type==JAPI_Const.J_OPENED)
			sendid();
	}

	public void windowClosed(WindowEvent e)
	{
		if(type==JAPI_Const.J_CLOSED)
			sendid();
	}

	public void windowIconified(WindowEvent e)
	{
		if(type==JAPI_Const.J_ICONIFIED)
			sendid();
	}

	public void windowDeiconified(WindowEvent e)
	{
		if(type==JAPI_Const.J_DEICONIFIED)
			sendid();
	}

	public void windowClosing(WindowEvent e)
	{
		if(type==JAPI_Const.J_CLOSING)
			sendid();
	}


	public void sendid()
	{
		if(debuglevel > 1) System.out.println("WindowListener for Object : "+this.id);
		try
		{
			as.sendInt(id);
		}
		catch(IOException exce) {}
	}

	public void setdebuglevel(int level)
	{
		debuglevel=level;
	}
}